package com.smallA.association.controller;

import com.smallA.association.bo.Result;
import com.smallA.association.bo.ResultAssociationDepartment;
import com.smallA.association.constant.UserConstant;
import com.smallA.association.pojo.Association;
import com.smallA.association.pojo.Department;
import com.smallA.association.service.AssociationService;
import com.smallA.association.utils.JwtUtils;
import com.smallA.association.vo.RegistrationData;
import com.smallA.association.vo.State;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author wanda
 * 社团相关类
 */
@RestController
public class AssociationController {
    @Resource
    private AssociationService associationService;

    /**
     * 通过社团数据更新对应的数据
     *
     * @param association 要更新的社团信息
     * @return 更新成功返回更新后的结果
     */
    @Secured(UserConstant.ASSOCIATION_WRITE_ACCESS)
    @RequestMapping("/Association/updateByAssociation")
    public Result<ResultAssociationDepartment> updateByAssociation(Association association,
                                                                   MultipartFile head,
                                                                   MultipartFile QRCode) {
        return associationService.updateAssociation(association, head, QRCode);
    }

    @Secured({UserConstant.ASSOCIATION_READ_ACCESS, UserConstant.MANAGER_READ_ACCESS})
    @RequestMapping("/Association/selectById")
    public Result<Association> selectById(@RequestBody RegistrationData data) {
        return associationService.selectById(data.getId());
    }

    @RequestMapping("/Association/selectByUser")
    public Result<Object> selectByUser(@RequestBody State data) {
        return associationService.selectByUser(JwtUtils.getUser());
    }

    @RequestMapping("/Association/updateByDepartment")
    public Result<Object> updateByDepartment(@RequestBody Department department) {
        return associationService.updateByDepartment(department);
    }

    @RequestMapping("/Association/uploadPhotoWall")
    public Result<Object> uploadPhotoWall(MultipartFile[] file, Integer aid, Integer[] id) {
        return associationService.uploadPhotoWall(file, aid, id);
    }

    @RequestMapping("/Association/selectPhotoWall")
    public Result<Object> selectPhotoWall(@RequestBody Association association) {
        return associationService.selectPhotoWall(association);
    }

    @RequestMapping("/Association/selectDepartmentById")
    public Result<Object> selectDepartmentById(@RequestBody Department department) {
        return associationService.updateByDepartment(department);
    }
}
